﻿using System;
using System.Threading.Tasks;
using WinRT.SIP.UILogic.Models;

namespace WinRT.SIP.UILogic.Repositories
{
    public class CallRepository : ICallRepository
    {
        private ContactInfo _currentContact = null;
        private bool _isIncoming = false;

        public bool IsIncoming
        {
            get { return _isIncoming; }
        }

        public void SetCurrentCallee(string phoneNumber, bool isIncoming)
        {
            _currentContact = null;

            //TODO: Do a phone number lookup to obtain the contact information.
            if (_currentContact == null)
            {
                _currentContact = new ContactInfo { PhoneNumber = phoneNumber };
                _isIncoming = isIncoming;
            }
        }

        public string GetCalleeDisplayName()
        {
            if (_currentContact == null)
            {
                return "";
            }
            return _currentContact.DisplayName;
        }

        public async Task MakeCallAsync(string phoneNumber)
        {
            //TODO: Make call from SIP service. Simulate with delay for now.
            await Task.Delay(5000);
        }

        public async Task ReceiveCallAsync()
        {
            //TODO: Receive call from SIP service. Simulate with delay for now.
            await Task.Delay(2000);
        }

        public async Task EndCallAsync()
        {
            //TODO: Call Hangup in the SIP service. Simulate with delay for now.
            await Task.Delay(2000);
        }
    }
}
